﻿using System.CodeDom;
using System.Collections.Generic;
using AutoUnitTest.Common;
using AutoUnitTest.Common.CodeAdapter;
using AutoUnitTest.Common.CodeGeneration;
using AutoUnitTest.Common.CodeGeneration.CS;
using NUnit.Framework;

namespace AutoUnitTest.Tests
{
    public class ClassGeneratorTest
    {
        [Test]
        public void CodeGenTest()
        {
            var target = new ClassGenerator();

            target.CreateClass("AsdZxc","System");
            target.AddMethod("Func1"
                , methodParameters: new MethodParameter() { Name = "p1", Type = "".GetType() }
                , returnValue: new MethodParameter() { Name = "ret", Type = 1.GetType() }
                , methodAccess: MemberAttributes.Public | MemberAttributes.Final | MemberAttributes.Static

                );

            string actual = target.GetCodeResult();

            Assert.IsTrue(actual == "namespace System\r\n{\r\n    \r\n    public class AsdZxc\r\n    {\r\n        public static int Func1(string p1)\r\n        {\r\n            return 0;\r\n        }\r\n    }\r\n}\r\n");
        }

        [Test]
        public void GenerateTestWithNamespaceTest()
        {
            Graph g = MoqStubsAndMocks.ClassGraph();
            var testAdapt = new GraphToCodeConvertor(g);
            string code = testAdapt.GetGeneratedClass("System.MoqClass", new MsTestGenerator());

            Assert.IsTrue(code == "namespace System\r\n{\r\n    using Microsoft.VisualStudio.TestTools.UnitTesting;\r\n    \r\n    [TestClass()]\r\n    public class MoqClassTest\r\n    {\r\n        [TestMethod()]\r\n        public int MoqFunc1_p1OfInt32_Test()\r\n        {\r\n            return 0;\r\n        }\r\n    }\r\n}\r\n");
        }

        [Test]
        public void GenerateMockWithNamespaceTest()
        {
            Graph g = MoqStubsAndMocks.ClassGraph();

            var mAdapt = new GraphToCodeConvertor(g);
            string code = mAdapt.GetGeneratedClass("System.MoqClass", new MockGenerator());

            Assert.AreEqual(code, "namespace System\r\n{\r\n    \r\n    public class MockMoqClass : MoqClass\r\n    {\r\n        public override int MoqFunc1(int p1)\r\n        {\r\n            return 0;\r\n        }\r\n    }\r\n}\r\n");
        }

        [Test]
        public void GenerateMockWithoutNamespaceTest()
        {
            Graph g = MoqStubsAndMocks.ClassGraph();

            var mAdapt = new GraphToCodeConvertor(g);
            string code = mAdapt.GetGeneratedClass("MoqClass", new MockGenerator());
            Assert.AreEqual(code, "public class MockMoqClass : MoqClass\r\n{\r\n    public override int MoqFunc1(int p1)\r\n    {\r\n        return 0;\r\n    }\r\n}\r\n");
        }
    }
}
